package com.yue92.datalife.common;

public class DatabaseContextHolder {

    private static ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static final String TYPE_MASTER = "master";
    public static final String TYPE_SLAVE = "slave";

    static String getType() {
        String type = contextHolder.get();
        if (type == null) {
            type = TYPE_MASTER;
        }
        return type;
    }

    static void setType(String type) {
        contextHolder.set(type);
    }

    static void clearType() {
        contextHolder.remove();
    }
}